package com.piece.admin.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.piece.core.framework.annotation.translate.DicTranslate;
import com.piece.core.framework.annotation.office.ImageRender;
import com.piece.core.framework.annotation.translate.JsonMask;
import com.piece.core.framework.annotation.translate.SelectTranslate;
import com.piece.core.framework.enums.MaskType;
import com.piece.core.framework.support.model.BaseEntity;
import com.piece.core.framework.support.response.Select;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@Entity
@NoArgsConstructor
@Table(name = "tb_sys_user")
@ApiModel(value = "系统用户表: tb_sys_user")
public class TbSysUser extends BaseEntity implements Serializable {

    @Id
    @Column(name = "user_id", length = 11)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "主键")
    private Long userId;

    @Column(name = "dept_id", length = 11)
    @ApiModelProperty(value = "部门主键")
    private Long deptId;

    @Transient
    @ApiModelProperty(value = "所属部门")
    private String deptName;

    @Column(name = "login_name", length = 30)
    @ApiModelProperty(value = "登陆名")
    private String loginName;

    @Column(name = "user_name", length = 30)
    @ApiModelProperty(value = "用户昵称")
    private String userName;

    @Column(name = "user_type", length = 2)
    @ApiModelProperty(value = "用户类型", notes = "00后台用户 01前台用户")
    private String userType;

    @Transient
    @DicTranslate(source = "user_type", dicType = "sys_user_type")
    @ApiModelProperty(value = "用户类型")
    private String userTypeName;

    @Column(name = "email", length = 50)
    @ApiModelProperty(value = "邮箱")
    private String email;

    @Column(name = "mobile", length = 11)
    @ApiModelProperty(value = "手机")
    private String mobile;

    @Column(name = "gender", length = 1)
    @ApiModelProperty(value = "性别", notes = "0男 1女 2未知")
    private String gender;

    @Transient
    @DicTranslate(source = "gender", dicType = "sys_user_sex")
    @ApiModelProperty(value = "性别")
    private String genderName;

    @ImageRender(width = 90, height = 100)
    @Column(name = "avatar", length = 150)
    @ApiModelProperty(value = "头像路径")
    private String avatar;

    @JsonIgnore
    @JsonMask(type = MaskType.PASSWORD)
    @Column(name = "password", length = 50)
    @ApiModelProperty(value = "密码")
    private String password;

    @JsonIgnore
    @JSONField(serialize = false)
    @Column(name = "salt", length = 20)
    @ApiModelProperty(value = "盐加密")
    private String salt;

    @Column(name = "birthday")
    @ApiModelProperty(value = "出生日期")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date birthday;

    @Transient
    @DicTranslate(source = "birthday", proxy = "config.getAge")
    @ApiModelProperty(value = "年龄")
    private int age;

    @Column(name = "city", length = 500)
    @ApiModelProperty(value = "所在城市")
    private String city;

    @Column(name = "job", length = 255)
    @ApiModelProperty(value = "职业")
    private String job;

    @Column(name = "signature", length = 2000)
    @ApiModelProperty(value = "签名")
    private String signature;

    @Column(name = "remark", length = 500)
    @ApiModelProperty(value = "备注")
    protected String remark;

    @Column(name = "status", length = 1)
    @ApiModelProperty(value = "帐号状态", notes = "0=正常,1=删除,2=停用")
    private String status;

    @Transient
    @ApiModelProperty(value = "帐号状态名称")
    @DicTranslate(source = "status", dicType = "sys_normal_disable")
    private String statusName;

    @Transient
    @ApiModelProperty(value = "岗位组")
    private String postIds;

    @Transient
    @ApiModelProperty(value = "岗位组名称")
    private String postNames;

    @Transient
    @ApiModelProperty(value = "岗位组下拉菜单")
    @SelectTranslate(proxy = "tbSysPostService.initSelect", target = "postIds")
    private List<Select.Entity> postSelect;

    @Transient
    @ApiModelProperty(value = "角色组")
    private String roleIds;

    @Transient
    @ApiModelProperty(value = "角色组名称")
    private String roleNames;

    @Transient
    @ApiModelProperty(value = "角色组下拉菜单")
    @SelectTranslate(proxy = "tbSysRoleService.initSelect", target = "roleIds")
    private List<Select.Entity> roleSelect;
}
